﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
using Newtonsoft.Json;
namespace LandAppraisal.Controllers
{
    public class RoleController : ApiController
    {
        AdminBLL adminbll = new AdminBLL();

        #region 获取角色列表
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string Get(string name)
        {
            List<SysRoles> list;
            if (name == null || name == "")
            {
                list = adminbll.GetList<SysRoles>().ToList();
            }
            else
            {
                list = adminbll.GetList<SysRoles>().Where(t => t.Roles_Name.Contains(name)).ToList();
            }
            return JsonConvert.SerializeObject(list);
        }
        #endregion

        #region 添加角色信息
        /// 添加角色信息
        /// </summary>
        /// <param name="value"></param>
        [HttpPost]
        public int Post([FromBody]SysRoles role)
        {
            return adminbll.Add<SysRoles>(role);
        }
        #endregion

        #region 修改角色信息
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="dept"></param>
        /// <returns></returns>
        [HttpPut]
        public bool Put([FromBody] SysRoles dept)
        {
            return adminbll.Update<SysRoles>(dept);
        }
        #endregion

        #region 根据角色编号删除角色信息
        /// <summary>
        /// 根据角色编号删除角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Delete(int id)
        {
            return adminbll.DeleteById<SysRoles>(id);
        }
        #endregion

        #region 修改状态
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public int UpdateState(int id, int state)
        {
            return adminbll.UpdateRoleState(id, state);
        }
        #endregion

    }
}
